#include "my_gui.h"

lv_obj_t* btn1;
lv_obj_t* btn2;
lv_obj_t* btn3;
lv_obj_t* btn4;

lv_obj_t* lable5;

unsigned int light = 0;

static void my_event_cb(lv_event_t *e)
{
  lv_obj_t* target = lv_event_get_target(e);
	if(target == btn1)
	{
	  light = 100;
		lv_label_set_text_fmt(lable5,"light:%d%%",light);
	}
	else if(target == btn2)
	{
	  if(light<100)light += 10;
		lv_label_set_text_fmt(lable5,"light:%d%%",light);
	}
	else if(target == btn3)
	{
	  if(light>0)light -=10;
		lv_label_set_text_fmt(lable5,"light:%d%%",light);
	}
	else if(target == btn4)
	{
	  light = 0;
		lv_label_set_text_fmt(lable5,"light:%d%%",light);
	}
	TIM3->CCR2 = light;
}

void my_gui(void)
{
	btn1 = lv_btn_create(lv_scr_act());
	lv_obj_set_size(btn1,120,60);
	lv_obj_set_style_bg_color(btn1,lv_color_hex(0x5DF55C),LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(btn1,lv_color_hex(0xFFFEFE),LV_STATE_PRESSED);
	lv_obj_set_pos(btn1,36,86);
	lv_obj_add_event_cb(btn1,my_event_cb,LV_EVENT_CLICKED,NULL);

	lv_obj_t* lable1 = lv_label_create(btn1);
	lv_label_set_text(lable1,"OPEN");
	lv_obj_set_style_text_color(lable1,lv_color_hex(0x000000),LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(lable1,&lv_font_montserrat_20,LV_STATE_DEFAULT);
	lv_obj_set_align(lable1,LV_ALIGN_CENTER);

	btn2 = lv_btn_create(lv_scr_act());
	lv_obj_set_size(btn2,120,60);
	lv_obj_set_style_bg_color(btn2,lv_color_hex(0x4553F5),LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(btn2,lv_color_hex(0xFFFEFE),LV_STATE_PRESSED);
	lv_obj_align_to(btn2,btn1,LV_ALIGN_OUT_RIGHT_MID,0,0);
	lv_obj_set_pos(btn2,164,86);
	lv_obj_add_event_cb(btn2,my_event_cb,LV_EVENT_CLICKED,NULL);

	lv_obj_t* lable2 = lv_label_create(btn2);
	lv_label_set_text(lable2,"LIGHT+");
	lv_obj_set_style_text_color(lable2,lv_color_hex(0x000000),LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(lable2,&lv_font_montserrat_20,LV_STATE_DEFAULT);
	lv_obj_set_align(lable2,LV_ALIGN_CENTER);

	btn3 = lv_btn_create(lv_scr_act());
	lv_obj_set_size(btn3,120,60);
	lv_obj_set_style_bg_color(btn3,lv_color_hex(0x4553F5),LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(btn3,lv_color_hex(0xFFFEFE),LV_STATE_PRESSED);
	lv_obj_align_to(btn3,btn1,LV_ALIGN_OUT_BOTTOM_MID,0,0);
	lv_obj_set_pos(btn3,36,154);
	lv_obj_add_event_cb(btn3,my_event_cb,LV_EVENT_CLICKED,NULL);

	lv_obj_t* lable3 = lv_label_create(btn3);
	lv_label_set_text(lable3,"LIGHT-");
	lv_obj_set_style_text_color(lable3,lv_color_hex(0x000000),LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(lable3,&lv_font_montserrat_20,LV_STATE_DEFAULT);
	lv_obj_set_align(lable3,LV_ALIGN_CENTER);

	btn4 = lv_btn_create(lv_scr_act());
	lv_obj_set_size(btn4,120,60);
	lv_obj_set_style_bg_color(btn4,lv_color_hex(0xF5241A),LV_STATE_DEFAULT);
	lv_obj_set_style_bg_color(btn4,lv_color_hex(0xFFFEFE),LV_STATE_PRESSED);
	lv_obj_align_to(btn4,btn2,LV_ALIGN_OUT_BOTTOM_MID,0,0);
	lv_obj_set_pos(btn4,164,154);
  lv_obj_add_event_cb(btn4,my_event_cb,LV_EVENT_CLICKED,NULL);

  lv_obj_t* lable4 = lv_label_create(btn4);
	lv_label_set_text(lable4,"CLOSE");
	lv_obj_set_style_text_color(lable4,lv_color_hex(0x000000),LV_STATE_DEFAULT);
	lv_obj_set_style_text_font(lable4,&lv_font_montserrat_20,LV_STATE_DEFAULT);
	lv_obj_set_align(lable4,LV_ALIGN_CENTER);

	lable5 = lv_label_create(lv_scr_act());
	lv_label_set_text_fmt(lable5,"light:%d%%",light);
	lv_obj_set_style_text_font(lable5,&lv_font_montserrat_20,LV_STATE_DEFAULT);
	lv_obj_align(lable5,LV_ALIGN_TOP_MID,0,15);
}
